package com.backend.securitiessystem.service.impl;

import com.backend.securitiessystem.dao.INewShareDao;
import com.backend.securitiessystem.dto.NewShareDto;
import com.backend.securitiessystem.pojo.NewShare;
import com.backend.securitiessystem.service.NewShareService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 新增共享服务impl
 *
 * @author LWY
 * @date 2024-05-23 03:38:41
 */
@Service
public class NewShareServiceImpl extends ServiceImpl<INewShareDao, NewShare> implements NewShareService,
        IService<NewShare> {

    public IPage<NewShareDto> selectPageWithCondition(int current, int size, QueryWrapper<NewShare> queryWrapper) {
        Page<NewShare> page1 = new Page<>(current, size);
        IPage<NewShare> newShareIPage = this.page(page1, queryWrapper);

        List<NewShareDto> newShareDtoList = new ArrayList<>();
        for (NewShare newShare : newShareIPage.getRecords()) {
            NewShareDto dto = new NewShareDto();
            dto.setName(newShare.getName());
            dto.setListingDate(newShare.getListingDate());
            newShareDtoList.add(dto);
        }

        Page<NewShareDto> newShareDtoPage = new Page<>();
        newShareDtoPage.setRecords(newShareDtoList);
        newShareDtoPage.setCurrent(current);
        newShareDtoPage.setSize(size);
        newShareDtoPage.setTotal(newShareIPage.getTotal());

        return newShareDtoPage;
    }

}
